package com.open.demo.mvvm.bean

/**
 *
 * @Author: hailong.qiu hailong.qiu@xgimi.com
 * @Maintainer: hailong.qiu hailong.qiu@xgimi.com
 * @Date: 2022/2/18
 * @Copyright: 2022 www.xgimi.com Inc. All rights reserved.
 */
sealed class Result<T>() {

    data class Success<T>(val code: Int= SUCCESS, val data: T): Result<T>()
    data class Loading<T>(val data:T): Result<T>()
    data class Failure<T>(val code: Int, val data:T): Result<T>()

    companion object {
        const val SUCCESS = 200
        const val LOADING = 110
        const val FAILURE = 250
    }

    override fun toString(): String {
        return when(this) {
            is Success<*> -> "Success[data=$data]"
            is Loading<T> -> "Loading[data=$data]"
            is Failure -> "Error[exception{errorCode=$code}]"
        }
    }

}